package com.bjdd.jdy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjdd.jdy.R;
import com.bjdd.jdy.entity.DealRecord;
import com.bjdd.jdy.util.DateUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/10.
 */

public class DealRecordAdapter extends RecyclerView.Adapter<DealRecordAdapter.ViewHolder> {


    private Context mContext;
    private List<DealRecord> data;

    public DealRecordAdapter(Context context, List<DealRecord> list) {
        this.mContext = context;
        this.data = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder viewHolder;
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_deal_record, null);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        DealRecord record = data.get(position);
        holder.tvOrderType.setText(record.getMsg());
        String money = "";
        if (record.isPositive()){
            money += "+";
        }else {
            money += "-";
        }
        money += "￥" +record.getMoney();
        holder.tvOrderMoney.setText(money);
        String date = DateUtils.formatDate(record.getCreateTime()/1000);
        String time = DateUtils.getTime(record.getCreateTime()/1000);
        holder.tvOrderDate.setText(date);
        holder.tvOrderTime.setText(time);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_order_type)
        TextView tvOrderType;
        @Bind(R.id.tv_order_money)
        TextView tvOrderMoney;
        @Bind(R.id.tv_order_date)
        TextView tvOrderDate;
        @Bind(R.id.tv_order_time)
        TextView tvOrderTime;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
